package com.dao.impl;

import com.dao.ICartdao;
import com.entity.Cart;
import com.utlils.DBManager;
import com.utlils.DBUtlils;

import java.util.List;

public class Cartdaoimpl implements ICartdao {


    @Override
    public Integer inserCart(Cart cart) {
        String sql="insert into cart(uid,pid,value,total) value (?,?,?,?)";
        return DBManager.inserCart(sql,cart);
    }


    /**
     * 查询是否存在
     * @param uid
     * @param pid
     * @return
     */
    @Override
    public Boolean findByUidPidCart(Integer uid, Integer pid) {
        String sql="select * from cart where uid=? and pid=?";
        return DBManager.CartExistence(sql,uid,pid);
    }

    /**
     * 根据当前的值 修改
     * @param value 修改的值
     * @param uid
     * @param pid
     * @return
     */
    @Override
    public Integer UpdateValue(Integer value,Integer uid, Integer pid) {
        String sql="update cart set value = ? where uid=? and pid=?";
        return DBManager.UpdateCartValue(sql,value,uid,pid);
    }

    /**
     * 查询当前value
     * @param uid
     * @param pid
     * @return
     */
    @Override
    public Integer findCartValue(Integer uid, Integer pid) {
        String sql="select value from cart where uid=? and pid=?";
        return DBManager.FindValue(sql,uid,pid);

    }


    @Override
    public Integer DleProduct(Integer uid, Integer pid) {
        String sql ="update cart set state = 2 where uid = ? and pid=?";
        return DBManager.DeleteCart(sql,uid,pid);
    }

    @Override
    public Integer UpDateSop(Integer id) {
        return null;
    }


    @Override
    public List<Integer> findByCart(Integer uid) {
        String sql="select pid from cart where uid=? and State=1";
        return DBManager.SelectCart(sql,uid);
    }

    @Override
    public Integer UpDateState(Integer id, Integer value) {
        String sql="Update cart set state=? where uid=?";
        return DBManager.UpDateState(sql,value,id);
    }


}
